/*
 * 文 件    名:  OrderQueryTranscationsModel.java
 * 创建日期:  2012-12-18下午2:09:33
 * 版          权:  Epro Technologies Co., Ltd. Copyright 2011-2012,  All rights reserved
 * 作          者:  xrj66010
 */
package com.weipu.common.facade.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.weipu.common.constants.ServerConstant;

/** 
 * @Description 订单查询模型
 * @version [版本号, 2012-12-18]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 * 
 * @author xrj66010
 */
public class OrderQueryTranscationsModel implements Serializable
{
    private static final long serialVersionUID = 9178856466418296360L;
    
    private int RecordCount;
    
    private int PageCount;
    
    private String ResponseResult;
    
    private List<Transactions> Transactionss;
    
    public static class Transactions implements Serializable
    {
        private static final long serialVersionUID = 3995007371792093614L;
        
        private long TransactionID;
        
        private String Timestamp;
        
        private String ActualAction;
        
        private String RawAction;
        
        private double Amount;
        
        private String CurrencyCode;
        
        private String CurrencyType;
        
        private int SiteID;
        
        private String CustomerID;
        
        private String TransactionResult;
        
        private String LastUpdateTime;
        
        public long getTransactionID()
        {
            return TransactionID;
        }
        
        public void setTransactionID(long transactionID)
        {
            TransactionID = transactionID;
        }
        
        public String getTimestamp()
        {
            return Timestamp;
        }
        
        public void setTimestamp(String timestamp)
        {
            Timestamp = timestamp;
        }
        
        public String getActualAction()
        {
            return ActualAction;
        }
        
        public void setActualAction(String actualAction)
        {
            ActualAction = actualAction;
        }
        
        public String getRawAction()
        {
            return RawAction;
        }
        
        public void setRawAction(String rawAction)
        {
            RawAction = rawAction;
        }
        
        public double getAmount()
        {
            return Amount;
        }
        
        public void setAmount(double amount)
        {
            Amount = amount;
        }
        
        public String getCurrencyCode()
        {
            return CurrencyCode;
        }
        
        public void setCurrencyCode(String currencyCode)
        {
            CurrencyCode = currencyCode;
        }
        
        public String getCurrencyType()
        {
            return CurrencyType;
        }
        
        public void setCurrencyType(String currencyType)
        {
            CurrencyType = currencyType;
        }
        
        public int getSiteID()
        {
            return SiteID;
        }
        
        public void setSiteID(int siteID)
        {
            SiteID = siteID;
        }
        
        public String getCustomerID()
        {
            return CustomerID;
        }
        
        public void setCustomerID(String customerID)
        {
            CustomerID = customerID;
        }
        
        public String getTransactionResult()
        {
            return TransactionResult;
        }
        
        public void setTransactionResult(String transactionResult)
        {
            TransactionResult = transactionResult;
        }
        
        public String getLastUpdateTime()
        {
            return LastUpdateTime;
        }
        
        public void setLastUpdateTime(String lastUpdateTime)
        {
            LastUpdateTime = lastUpdateTime;
        }
        
    }
    
    public int getRecordCount()
    {
        return RecordCount;
    }
    
    public void setRecordCount(int recordCount)
    {
        RecordCount = recordCount;
    }
    
    public int getPageCount()
    {
        return PageCount;
    }
    
    public void setPageCount(int pageCount)
    {
        PageCount = pageCount;
    }
    
    public String getResponseResult()
    {
        return ResponseResult;
    }
    
    public void setResponseResult(String responseResult)
    {
        ResponseResult = responseResult;
    }
    
    public List<Transactions> getTransactionss()
    {
        return Transactionss;
    }
    
    public void setTransactionss(List<Transactions> transactionss)
    {
        Transactionss = transactionss;
    }
    
    @Override
    public String toString()
    {
        return tojson().toString();
    }
    
    /**
      * 实体转换为json对象
      * @return  [参数说明]
      * @return JSONObject [返回类型说明]
      * @exception throws [违例类型] [违例说明]
      * @see [类、类#方法、类#成员]
      */
    public JSONObject tojson()
    {
        JSONObject json = new JSONObject();
        try
        {
            if (0 != RecordCount)
            {
                json.put(ServerConstant.Order.RECORDCOUNT, RecordCount);
            }
            if (0 != PageCount)
            {
                json.put(ServerConstant.Order.PAGECOUNT, PageCount);
            }
            if (null != ResponseResult)
            {
                json.put(ServerConstant.Order.RESPONSERESULT, ResponseResult);
            }
            for (int i = 0; i < Transactionss.size(); i++)
            {
                if (0 != Transactionss.get(i).TransactionID)
                {
                    json.put(ServerConstant.Order.TRANSACTIONID, Transactionss.get(i).TransactionID);
                }
                if (null != Transactionss.get(i).Timestamp)
                {
                    json.put(ServerConstant.Order.TIMESTAMP, Transactionss.get(i).Timestamp);
                }
                if (null != Transactionss.get(i).ActualAction)
                {
                    json.put(ServerConstant.Order.ACTUALACTION, Transactionss.get(i).ActualAction);
                }
                if (null != Transactionss.get(i).RawAction)
                {
                    json.put(ServerConstant.Order.RAWACTION, Transactionss.get(i).RawAction);
                }
                json.put(ServerConstant.Order.AMOUNT, Transactionss.get(i).Amount);
                if (null != Transactionss.get(i).CurrencyCode)
                {
                    json.put(ServerConstant.Order.CURRENCYCODE, Transactionss.get(i).CurrencyCode);
                }
                if (null != Transactionss.get(i).CurrencyType)
                {
                    json.put(ServerConstant.Order.CURRENCYTYPE, Transactionss.get(i).CurrencyType);
                }
                if (0 != Transactionss.get(i).SiteID)
                {
                    json.put(ServerConstant.Order.SITEID, Transactionss.get(i).SiteID);
                }
                if (null != Transactionss.get(i).CustomerID)
                {
                    json.put(ServerConstant.Order.CUSTOMERID, Transactionss.get(i).CustomerID);
                }
                if (null != Transactionss.get(i).TransactionResult)
                {
                    json.put(ServerConstant.Order.TRANSACTIONRESULT, Transactionss.get(i).TransactionResult);
                }
                if (null != Transactionss.get(i).LastUpdateTime)
                {
                    json.put(ServerConstant.Order.LASTUPDATETIME, Transactionss.get(i).LastUpdateTime);
                }
            }
        }
        catch (JSONException e)
        {
            e.printStackTrace();
        }
        return json;
    }
    
    public static OrderQueryTranscationsModel json2orderquery(JSONObject json)
    {
        if (null == json)
        {
            return null;
        }
        OrderQueryTranscationsModel orderQuery = new OrderQueryTranscationsModel();
        orderQuery.setRecordCount(json.optInt(ServerConstant.Order.RECORDCOUNT));
        orderQuery.setPageCount(json.optInt(ServerConstant.Order.PAGECOUNT));
        if (json.optString(ServerConstant.Order.RESPONSERESULT) != JSONObject.NULL
            && !json.isNull(ServerConstant.Order.RESPONSERESULT))
        {
            orderQuery.setResponseResult(json.optString(ServerConstant.Order.RESPONSERESULT));
        }
        try
        {
            JSONArray transe = json.getJSONArray(ServerConstant.Order.TRANSACTIONS);
            Transactions tran = null;
            ArrayList<Transactions> list = new ArrayList<Transactions>();
            for (int i = 0; i < transe.length(); i++)
            {
                tran = new Transactions();
                tran.TransactionID = transe.getJSONObject(i).optLong(ServerConstant.Order.TRANSACTIONID);
                if (transe.getJSONObject(i).optString(ServerConstant.Order.TIMESTAMP) != JSONObject.NULL
                    && !transe.getJSONObject(i).isNull(ServerConstant.Order.TIMESTAMP))
                {
                    tran.Timestamp = transe.getJSONObject(i).optString(ServerConstant.Order.TIMESTAMP);
                }
                if (transe.getJSONObject(i).optString(ServerConstant.Order.ACTUALACTION) != JSONObject.NULL
                    && !transe.getJSONObject(i).isNull(ServerConstant.Order.ACTUALACTION))
                {
                    tran.ActualAction = transe.getJSONObject(i).optString(ServerConstant.Order.ACTUALACTION);
                }
                if (transe.getJSONObject(i).optString(ServerConstant.Order.RAWACTION) != JSONObject.NULL
                    && !transe.getJSONObject(i).isNull(ServerConstant.Order.RAWACTION))
                {
                    tran.RawAction = transe.getJSONObject(i).optString(ServerConstant.Order.RAWACTION);
                }
                tran.Amount = transe.getJSONObject(i).optDouble(ServerConstant.Order.AMOUNT);
                if (transe.getJSONObject(i).optString(ServerConstant.Order.CURRENCYCODE) != JSONObject.NULL
                    && !transe.getJSONObject(i).isNull(ServerConstant.Order.CURRENCYCODE))
                {
                    tran.CurrencyCode = transe.getJSONObject(i).optString(ServerConstant.Order.CURRENCYCODE);
                }
                if (transe.getJSONObject(i).optString(ServerConstant.Order.CURRENCYTYPE) != JSONObject.NULL
                    && !transe.getJSONObject(i).isNull(ServerConstant.Order.CURRENCYTYPE))
                {
                    tran.CurrencyType = transe.getJSONObject(i).optString(ServerConstant.Order.CURRENCYTYPE);
                }
                tran.SiteID = transe.getJSONObject(i).optInt(ServerConstant.Order.SITEID);
                if (transe.getJSONObject(i).optString(ServerConstant.Order.CUSTOMERID) != JSONObject.NULL
                    && !transe.getJSONObject(i).isNull(ServerConstant.Order.CUSTOMERID))
                {
                    tran.CustomerID = transe.getJSONObject(i).optString(ServerConstant.Order.CUSTOMERID);
                }
                if (transe.getJSONObject(i).optString(ServerConstant.Order.TRANSACTIONRESULT) != JSONObject.NULL
                    && !transe.getJSONObject(i).isNull(ServerConstant.Order.TRANSACTIONRESULT))
                {
                    tran.TransactionResult = transe.getJSONObject(i).optString(ServerConstant.Order.TRANSACTIONRESULT);
                }
                if (transe.getJSONObject(i).optString(ServerConstant.Order.LASTUPDATETIME) != JSONObject.NULL
                    && !transe.getJSONObject(i).isNull(ServerConstant.Order.LASTUPDATETIME))
                {
                    tran.LastUpdateTime = transe.getJSONObject(i).optString(ServerConstant.Order.LASTUPDATETIME);
                }
                list.add(tran);
            }
            orderQuery.setTransactionss(list);
        }
        catch (JSONException e)
        {
            e.printStackTrace();
        }
        return orderQuery;
    }
    
    /**
     * json转换为实体
     * @param jsonString
     * @return  [参数说明]
     * @return OrderQueryTranscationsModel [返回类型说明]
     * @exception throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     */
    public static OrderQueryTranscationsModel json2orderquery(String jsonString)
    {
        if (null == jsonString || "".equals(jsonString.trim()))
        {
            return null;
        }
        
        OrderQueryTranscationsModel model = null;
        try
        {
            JSONObject json = new JSONObject(jsonString);
            model = json2orderquery(json);
        }
        catch (JSONException e)
        {
            
        }
        return model;
    }
    
}
